var vm = new Vue({
    el: '#my_app1',
    delimiters: ['[[',']]'],
    data: {
        token: '',
        user_head_img: '',
        movie_info: {},
        show_five_stardom: [],
        stardom_length: '',

    },
    mounted(){
        this.token = getCookie('token');
        this.getUserHead();
        this.getMovieDetail();
    },
    methods: {
        getMovieDetail(){

            var m_id = window.location.search.substring(1).split("=")[1];

            var url = host + '/movie/get_movie_detail/' + m_id
            axios.get(url,{
                headers: {
                    'Authorization': 'JWT ' + this.token
                },
                responseType: 'json',
                withCredentials:true,
            })
            .then(dat => {
                if (dat.data.code == 0){
                    this.movie_info = dat.data.movie_info
                    if (this.movie_info.time == "None"){
                        this.movie_info.time = undefined
                    }
                    this.show_five_stardom = dat.data.movie_info.stardom.slice(0,5)
                    this.stardom_length = dat.data.movie_info.stardom.length


                }else{
                    window.location.href = '/404.html'
                }
                
            }).catch(err => {
                console.log(err);
                
            })
            
        },
        getUserHead() {
            var url = host + '/user/user_head/'
            axios.get(url,{
                headers: {
                    'Authorization': 'JWT ' + this.token
                },
                responseType: 'json',
                withCredentials:true,
            })
            .then(dat => {
                if (dat.data.code == 0){
                    // console.log(dat.data.img_url);
                    
                    this.user_head_img = dat.data.img_url
                }else{
                    alert(dat.data.errmsg);
                    window.location.reload();
                }
            }).catch(err => {
                console.log(err);
                
            })
        },
        logoutfunc: function () {
            var url = host + '/user/logout/';
            axios.delete(url,{
                responseType: 'json',
                withCredentials:true,
            })
                .then(respone => {
                    location.href = '/index.html'
                })
                .catch(error => {
                    console.log(error.respone);
                    
                })
        }
    }
})